<template>
  <div >
    <van-list class="searchresults"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="(item,index) in list" :key="index" :title="item.title" />
    </van-list>
  </div>
</template>
<script>
import {searchResults} from "@/api/user"//搜索结果的接口
export default {
  props:{
    searchTexts:{
      type:String,
      required:true
    }
  },
  created(){
    // console.log(searchResults)
    
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page:1,
      per_page:20
    };
  },
    methods: {
    async onLoad() {
      var {data}= await searchResults({
          page:this.page,
          per_page:this.per_page,
          q:this.searchTexts

      })
      this.list.push(...data.data.results)
      this.loading = false//关闭本次的请求
      if (data.data.results.length){
        this.page++


      }else {
        this.finished = true
      }
      // console.log(this.list)
    },
  },
};
</script>
<style scoped lang="less">
/deep/.van-cell__title {
    text-align: left;
}
.searchresults {
    position: fixed;
    top: 54px;
    right: 0;
    left: 0;
    bottom: 0;
    overflow-y:auto ;
}

</style>